package com.dailyblue.java.net;

import java.net.*;
import java.io.*;

public class DemoB {
    public static void main(String[] args) {
        try {
            URL url = new URL("https://mbd.baidu.com/newspage/data/landingsuper?context=%7B%22nid%22%3A%22news_9562732370843948988%22%7D&n_type=-1&p_from=-1");
            URLConnection urlConnection = url.openConnection();
            HttpURLConnection connection = null;
            if (urlConnection instanceof HttpURLConnection) {
                connection = (HttpURLConnection) urlConnection;
            } else {
                System.out.println("请输入 URL 地址");
                return;
            }
            InputStreamReader reader = new InputStreamReader(connection.getInputStream());
            BufferedReader in = new BufferedReader(reader);
            String urlString = "";
            String current;
            while ((current = in.readLine()) != null) {
                urlString += current + "\n";
            }
            System.out.println(urlString);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
